<template>
  <div class="goods-list">
    <div class="goods-item" v-for="item in goodsList" :key="item.id" @click="goDetail(item.id)">
      <img :src="item.src" alt />
      <h1>{{item.des}}</h1>
      <div class="info">
        <p class="price">
          <span class="now">{{item.sellPrice}}</span>
          <del>{{item.totalPrice}}</del>
        </p>
        <p class="sell">
          <span>{{item.state}}</span>
          <span>剩{{item.storage}}件</span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      goodsList: []
    };
  },
  created() {
    this.getGoodsList();
  },
  methods: {
    getGoodsList() {
      this.$axios.get("../json/products.json").then(res => {
        this.goodsList = res.data;
        //console.log(this.goodsList);
      });
    },
    goDetail(id) {
      this.$router.push("/home/goodsinfo/" + id);
    }
  }
};
</script>

<style lang="scss" scoped>
.goods-list {
  padding: 7px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .goods-item {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 293px;
    width: 49%;
    border: 1px solid #ccc;
    margin: 4px 0;
    padding: 2px;
    img {
      width: 100%;
      height: 170px;
    }
    h1 {
      font-size: 14px;
    }
    .info {
      background-color: #eee;
      p {
        margin: 0;
        padding: 5px;
      }
      .price {
        .now {
          color: red;
          font-weight: bold;
          font-size: 16px;
        }
        del {
          font-size: 12px;
          margin-left: 10px;
        }
      }
      .sell {
        display: flex;
        justify-content: space-between;
      }
    }
  }
}
</style>